package com.redxun.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.support.ResourceBundleMessageSource;

/**
 * 功能: 国际化配置,解决linux下的问题.
 *
 * @author ASUS
 * @date 2024/3/20 9:37
 */
@Configuration
public class MessagingConfig {

    @Value("${spring.messages.basename}")
    private String basename;

    @Value("${spring.messages.encoding}")
    private String encoding;

    @Bean
    @Primary
    public MessageSource messageSource() {

        ResourceBundleMessageSource messageSource = new
                ResourceBundleMessageSource();

        messageSource.setBasenames(basename.split("[,]"));
        messageSource.setDefaultEncoding(encoding);
        return messageSource;
    }

}
